﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using BaseDatos;

namespace SCHD
{
    public partial class WFAtributos_edit : TDV.Controles.Base.WinForm.BaseForm_Tipo01
    {
        private string CodAtributo = "";
        private string flgunico = "";
        public WFAtributos_edit(string codatrib)
        {
            this.CodAtributo = codatrib;
            InitializeComponent();
        }
        public void Buscar()
        {
            try
            {
                DataSet ds = ConexionBaseDatos.Conexion.CrearDataSet("select codatrib,dscatrib,flgunico from chdatributo where codatrib = '" + CodAtributo + "' and flgeli ='0'", CommandType.Text);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    TxtCodigo.Text = ds.Tables[0].Rows[0][0].ToString();
                    TxtDescripcion.Text = ds.Tables[0].Rows[0][1].ToString();
                    flgunico = ds.Tables[0].Rows[0][2].ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
         
         
         
        }

        private void WFAtributos_edit_Load(object sender, EventArgs e)
        {
            Buscar();
        }

        private void BtnCancelar_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }

        private void BtnAceptar_Click(object sender, EventArgs e)
        {
            try
            {
                EBAtributo atributo = new EBAtributo();
                atributo.CodigoAtributo = TxtCodigo.Text;
                atributo.Descripcion = TxtDescripcion.Text;
                atributo.FlagUnico = flgunico;
                atributo.Grabar();
                DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
